<?php
class  facebook_link_widget extends WP_Widget {
function facebook_link_widget() {
global $themename;
    $widget_ops = array('description' => __('Show Facebook Icon') );
	parent::WP_Widget(false, $name=$themename.' - Facebook',$widget_ops);
}

/**
 * Displays Video widget on blog.
 */
function widget($args, $instance) {
	extract( $args );
	// If not title, use the name of the category.
    global $page_id_num1;
    if($page_id_num1&&$page_id_num1!=''){
        $link_to_like = get_permalink($page_id_num1);
    }else{
        $link_to_like = 'http://www.facebook.com/Lefruitduhasard';
    }
    
    echo $before_widget;
    echo '<br />';
    echo '<div class="textwidget">';
    if( $instance["facebooklink"] ) {
        $facebooklink =$instance["facebooklink"];
       }else{
        $facebooklink='#';
       }
       ?> 

      <table class="facebook_like_bt"><tbody><tr>
    <td class="facebook_like_td">
        <a href="<?php echo $facebooklink; ?>" target="_blank"><img class="no_border" alt="images" width="27" height="53" src="<?php bloginfo('template_url'); ?>/images/footer_img/logo_fb.png"/></a>
        <div style="clear:both;"></div></td>
    <td style="vertical-align:top; padding-top:3px;">
       <!-- <div class="facebook_like_button_holder">-->
            <?php
           // echo '<div class="facebook_like_content_iframe">';
            echo '<fb:like href="'.$link_to_like.'" send="false" layout="button_count" width="58" show_faces="false"></fb:like>';
           // echo '</div>';
           //  j\'aime';
   //echo '<iframe name="facebook_like_iframe" id="facebook_like_iframe" class="facebook_like_iframe" src="//www.facebook.com/plugins/like.php?href='.$link_to_like.'&amp;locale=fr_FR&amp;send=false&amp;layout=button_count&amp;width=58&amp;show_faces=false&amp;action=like&amp;colorscheme=dark&amp;font&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:58px; height:21px;" allowTransparency="true"><p>j\'aime</p></iframe>';
   // echo '<iframe name="myIframe" ="myIframe" id="myIframe" ="myIframe" scrolling="yes"  width="600" height="250"></iframe>';
  // echo '<iframe name="facebook_like_iframe2"></iframe>';
            ?>
         <!-- <div class="fake_facebook_button"><p>j'aime</p></div>
        </div>-->
    </td>
</tr></tbody></table>
       
    <?php
    echo '</div>';
	echo $after_widget;
}

/**
 * Form processing....
 */
function update($new_instance, $old_instance) {
    $instance = $old_instance;
    $instance['facebooklink'] =  $new_instance['facebooklink'] ;    
   	return $instance;
}

/**
 *  form.
 */
function form($instance) {
?>
<p>
    <label for="<?php echo $this->get_field_id("facebooklink"); ?>">
    <?php _e( 'Facebook link','LFDH'); ?>
    :
    </label>
</p>
<p>
    <input class="widefat" id="<?php echo $this->get_field_id("facebooklink"); ?>" name="<?php echo $this->get_field_name("facebooklink"); ?>" type="text" value="<?php if($instance["facebooklink"]) { echo esc_attr($instance["facebooklink"]); } ?>" />
</p>
<p>
    <label>
    <?php _e('EX: <a href="https://www.facebook.com/pages/86Solutions/160315314057130">https://www.facebook.com/pages/86Solutions/160315314057130</a>'); ?>
    </label>
</p>
<?php

}

}
add_action( 'widgets_init', create_function('', 'return register_widget("facebook_link_widget");') );
?>